/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jmooc.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;

/**
 *
 * @author Group
 */
@Entity
@Table(name="usertable")
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @Column(unique=true)
    private String email;
    private String password;
    private String firstName;
    private String lastName;
    
    // Pour le webservice
    private String token;

    @Temporal(javax.persistence.TemporalType.DATE)
    private Date tokenExpiration;
    
    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Date getTokenExpiration() {
        return tokenExpiration;
    }

    public void setTokenExpiration(Date tokenExpiration) {
        this.tokenExpiration = tokenExpiration;
    }
    
    
    
    @OneToMany(fetch= FetchType.EAGER) @JoinColumn
    private List<ReadCourse> readCourses;

    @ManyToOne @JoinColumn
    private UserCertification userCertification;
    
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public List<ReadCourse> getReadCourses() {
        return readCourses;
    }

    public void setReadCourses(List<ReadCourse> readCourses) {
        this.readCourses = readCourses;
    }

    public UserCertification getUserCertification() {
        return userCertification;
    }

    public void setUserCertification(UserCertification userCertification) {
        this.userCertification = userCertification;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.jmooc.entity.User[ id=" + id + " ]";
    }
    
}
